package com.book.controller;

import com.book.dto.PostPage;
import com.book.entity.Post;
import com.book.service.PostService;
import com.book.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
/**
 * @author yicheng
 */
@RestController
@RequestMapping("/post")
public class PostController {
    @Autowired
    private PostService postService;

    @PostMapping("/getList")
    public ResponseResult getList(@RequestBody PostPage postPage){
        return postService.getList(postPage);
    }

    /**
     * 发表帖子
     * @param userId
     * @param post
     * @return
     */
    @PostMapping("/publishPost")
    public ResponseResult publishPost(@RequestParam String userId, @RequestBody Post post){
        return postService.publishPost(userId,post);
    }

    /**
     * 获取一个帖子的内容信息
     * @param id
     * @return
     */
    @GetMapping("/getOne")
    public ResponseResult getOne(@RequestParam int id){
        return postService.getOne(id);
    }

    /**
     * 用户获取自己的帖子，感觉没必要分页，按照时间倒序就行吧应该。
     * @param postPage--包括了分页参数和查询条件-根据title来查
     * @return
     */
    @PostMapping("/getPosts")
    public ResponseResult getPosts(@RequestBody PostPage postPage){
        return postService.getPosts(postPage);
    }

    //用户点击自己的某个帖子的修改获取的接口
    @GetMapping("/getPost")
    public ResponseResult getPost(@RequestParam int id){
        return postService.getPost(id);
    }

    //删除帖子
    @GetMapping("/deletePost")
    public ResponseResult deletePost(@RequestParam int id){
        return postService.deletePost(id);
    }

    @PostMapping("/getAllPosts")
    public ResponseResult getAllPosts(@RequestBody PostPage postPage){
        return postService.getAllPosts(postPage);
    }

}
